package mulMan.domain;

import java.util.Observable;
import java.util.Observer;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class AudioFileFactory implements Observer, ApplicationContextAware{
	
	private PlaylistModel playlist;
	private AudioFileModel audioFile;
	private ApplicationContext applicationContext;
	
	public AudioFileFactory() {
	}
	
	public AudioFileModel addAudioFileToPlaylist(PlaylistModel playlist) {
		this.playlist = playlist;
		audioFile = (AudioFileModel) applicationContext.getBean("audioFileModel");
		audioFile.addObserver(this);
		return audioFile;
	}

	public void update(Observable o, Object arg) {

		if (arg == "id") {
			playlist.addAudioFileToPlaylist(audioFile);
			audioFile.deleteObserver(this);
		}
	}

	public void setApplicationContext(ApplicationContext arg0)
			throws BeansException {
		this.applicationContext = arg0;
	}
}
